package com.rtos.vo.file.diskPane;

import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Effect;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.text.Font;

public class BlockPane extends StackPane {
    public Rectangle rectangle;
    private Label indexLabel;
    private int index;
    private int status;
    public static final int UNUSED_STATUS = 0;
    public static final int USED_STATUS = 1;
    public static final int DAMAGE_STATUS = -1;
    public DropShadow dropShadow=new DropShadow();

    public BlockPane(int index) {
        this.rectangle = new Rectangle(30.0D, 25.0D, Color.ALICEBLUE);
        this.rectangle.setStroke(Color.BLACK);
        this.rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
        this.index = index;
        this.status = 0;
        this.indexLabel = new Label(index + "");
        this.indexLabel.setFont(Font.font(10.0D));
       // this.dropShadow = new DropShadow();
        this.getChildren().addAll(new Node[]{this.rectangle, this.indexLabel});
        this.initializeListener();
    }

    private void initializeListener() {
        this.setOnMouseEntered(new EventHandler<MouseEvent>() {
            public void handle(MouseEvent event) {
                rectangle.setEffect(BlockPane.this.dropShadow);

            }
        });
        this.setOnMouseExited(new EventHandler<MouseEvent>() {
            public void handle(MouseEvent event) {
                rectangle.setEffect((Effect)null);
            }
        });
    }

    public int getIndex() {
        return this.index;
    }

    public void setUsed() {
        this.status = 1;
        this.rectangle.setFill(Color.GREEN);
    }
    public void setUnUsed() {
        this.status = 1;
        this.rectangle.setFill(Color.GREEN);
    }



    public void setDamage() {
        this.status = -1;
        this.rectangle.setFill(Color.RED);
    }

    public int getStatus() {
        return this.status;
    }
}
